package service.impl;

import dao.UserDAO;
import dao.impl.UserDAOImpl;
import pojo.User;
import service.UserService;

/**
 * @author lq
 * @create 2021/1/9
 */

public class UserServiceImpl implements UserService {
    private UserDAO userDAO = new UserDAOImpl();

    @Override
    public boolean registUser(User user) {
        return userDAO.saveUser(user) != null;
    }

    @Override
    public Integer login(String account, String password) {
        User user = userDAO.queryUserByAccountAndPassword(account, password);
        return user.getId();
    }

    @Override
    public boolean existUserName(String account) {
        return userDAO.queryUserByAccount(account) != null;
    }

    @Override
    public User findUserByUserName(String account) {
        return userDAO.queryUserByAccount(account);
    }

    @Override
    public boolean updateUser(User user) {
        return userDAO.updateUser(user)==1;
    }

    @Override
    public boolean updatePwd(String email, String password) {
        return userDAO.updatePwd(email, password)==1;
    }

    //    @Override
//    public boolean deleteUser(String account) {
//        User user = userDAO.queryUserByAccount(account);
//        user.setAccount("123");
//        System.out.println(user);
//        if(userDAO.updateUser(user)==1){
//            System.out.println("ok.....");
//            return true;
//        }else{
//            System.out.println("error.......");
//            return false;
//        }
//
//    }

//    @Override
//    public boolean saveUser(User user) {
//        return userDAO.saveUser(user)==1;
//    }
}
